package br.unipar.calculadora.view;

import br.unipar.calculadora.Calculadora;
import br.unipar.calculadora.calculo.Calculo;
import br.unipar.calculadora.calculo.Soma;

public class CalculadoraFrame extends javax.swing.JFrame {

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        displayTextField = new javax.swing.JTextField();
        seteButton = new javax.swing.JButton();
        oitoButton = new javax.swing.JButton();
        noveButton = new javax.swing.JButton();
        divisaoButton = new javax.swing.JButton();
        quatroButton = new javax.swing.JButton();
        cincoButton = new javax.swing.JButton();
        seisButton = new javax.swing.JButton();
        multiplicacaoButton = new javax.swing.JButton();
        umButton = new javax.swing.JButton();
        doisButton = new javax.swing.JButton();
        tresButton = new javax.swing.JButton();
        subtracaoButton = new javax.swing.JButton();
        zeroButton = new javax.swing.JButton();
        pontoButton = new javax.swing.JButton();
        adicaoButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        seteButton.setText("7");
        seteButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                seteButtonActionPerformed(evt);
            }
        });

        oitoButton.setText("8");
        oitoButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                oitoButtonActionPerformed(evt);
            }
        });

        noveButton.setText("9");
        noveButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                noveButtonActionPerformed(evt);
            }
        });

        divisaoButton.setText("/");

        quatroButton.setText("4");
        quatroButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                quatroButtonActionPerformed(evt);
            }
        });

        cincoButton.setText("5");
        cincoButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cincoButtonActionPerformed(evt);
            }
        });

        seisButton.setText("6");
        seisButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                seisButtonActionPerformed(evt);
            }
        });

        multiplicacaoButton.setText("*");

        umButton.setText("1");
        umButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                umButtonActionPerformed(evt);
            }
        });

        doisButton.setText("2");
        doisButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                doisButtonActionPerformed(evt);
            }
        });

        tresButton.setText("3");
        tresButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tresButtonActionPerformed(evt);
            }
        });

        subtracaoButton.setText("-");

        zeroButton.setText("0");
        zeroButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                zeroButtonActionPerformed(evt);
            }
        });

        pontoButton.setText(".");
        pontoButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                pontoButtonActionPerformed(evt);
            }
        });

        adicaoButton.setText("+");
        adicaoButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                adicaoButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(displayTextField, javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(zeroButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(umButton, javax.swing.GroupLayout.Alignment.LEADING, 0, 0, Short.MAX_VALUE)
                                    .addComponent(quatroButton, javax.swing.GroupLayout.Alignment.LEADING, 0, 0, Short.MAX_VALUE)
                                    .addComponent(seteButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(doisButton, 0, 0, Short.MAX_VALUE)
                                    .addComponent(cincoButton, 0, 0, Short.MAX_VALUE)
                                    .addComponent(oitoButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(pontoButton, 0, 0, Short.MAX_VALUE)
                            .addComponent(tresButton, 0, 0, Short.MAX_VALUE)
                            .addComponent(seisButton, 0, 0, Short.MAX_VALUE)
                            .addComponent(noveButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(subtracaoButton, 0, 0, Short.MAX_VALUE)
                                    .addComponent(divisaoButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(multiplicacaoButton, javax.swing.GroupLayout.DEFAULT_SIZE, 55, Short.MAX_VALUE)))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(adicaoButton, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(displayTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(seteButton)
                    .addComponent(oitoButton)
                    .addComponent(noveButton)
                    .addComponent(divisaoButton))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(quatroButton)
                    .addComponent(cincoButton)
                    .addComponent(seisButton)
                    .addComponent(multiplicacaoButton))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(umButton)
                    .addComponent(doisButton)
                    .addComponent(tresButton)
                    .addComponent(subtracaoButton))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(zeroButton)
                    .addComponent(pontoButton)
                    .addComponent(adicaoButton))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void seteButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_seteButtonActionPerformed
        populaDisplay(7);
    }//GEN-LAST:event_seteButtonActionPerformed

    private void oitoButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_oitoButtonActionPerformed
        populaDisplay(8);
    }//GEN-LAST:event_oitoButtonActionPerformed

    private void noveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_noveButtonActionPerformed
        populaDisplay(9);
    }//GEN-LAST:event_noveButtonActionPerformed

    private void quatroButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_quatroButtonActionPerformed
        populaDisplay(4);
    }//GEN-LAST:event_quatroButtonActionPerformed

    private void cincoButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cincoButtonActionPerformed
        populaDisplay(5);
    }//GEN-LAST:event_cincoButtonActionPerformed

    private void seisButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_seisButtonActionPerformed
        populaDisplay(6);
    }//GEN-LAST:event_seisButtonActionPerformed

    private void umButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_umButtonActionPerformed
        populaDisplay(1);
    }//GEN-LAST:event_umButtonActionPerformed

    private void doisButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_doisButtonActionPerformed
        populaDisplay(2);
    }//GEN-LAST:event_doisButtonActionPerformed

    private void tresButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tresButtonActionPerformed
        populaDisplay(3);
    }//GEN-LAST:event_tresButtonActionPerformed

    private void zeroButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_zeroButtonActionPerformed
        populaDisplay(0);
    }//GEN-LAST:event_zeroButtonActionPerformed

    private void pontoButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pontoButtonActionPerformed
        populaDisplay(".");
    }//GEN-LAST:event_pontoButtonActionPerformed

    Calculadora hp = new Calculadora();

    public CalculadoraFrame() {
        initComponents();

        String display = String.valueOf( hp.display );
        displayTextField.setText(display);
    }

    private void adicaoButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_adicaoButtonActionPerformed
        double valor = Double.parseDouble( displayTextField.getText() );

        Calculo soma = new Soma(valor);
        hp.calcular(soma);

        displayTextField.setText( String.valueOf( hp.display ) );
    }//GEN-LAST:event_adicaoButtonActionPerformed

    public void populaDisplay(int valor) {
        String display = displayTextField.getText();
        display += valor;
        displayTextField.setText(display);
    }

    public void populaDisplay(double valor) {
        String display = displayTextField.getText();
        display += valor;
        displayTextField.setText(display);
    }

    public void populaDisplay(String valor) {
        String display = displayTextField.getText();
        display += valor;
        displayTextField.setText(display);
    }

    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new CalculadoraFrame().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton adicaoButton;
    private javax.swing.JButton cincoButton;
    private javax.swing.JTextField displayTextField;
    private javax.swing.JButton divisaoButton;
    private javax.swing.JButton doisButton;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JButton multiplicacaoButton;
    private javax.swing.JButton noveButton;
    private javax.swing.JButton oitoButton;
    private javax.swing.JButton pontoButton;
    private javax.swing.JButton quatroButton;
    private javax.swing.JButton seisButton;
    private javax.swing.JButton seteButton;
    private javax.swing.JButton subtracaoButton;
    private javax.swing.JButton tresButton;
    private javax.swing.JButton umButton;
    private javax.swing.JButton zeroButton;
    // End of variables declaration//GEN-END:variables

}
